function compose(...funcs) {
  if (funcs.length === 0) {
    return (arg) => arg
  }

  if (funcs.length === 1) {
    return funcs[0]
  }

  return funcs.reduce((a, b) => {
    return (...args) => {
      return a(b(...args))
    }
  })
}

const f1 = num => {
  return num + 3
}

const f2 = num => {
  return num + 5
}

const f3 = num => {
  return num + 1
}

const r = compose(f1, f2, f3)

const result = r(0)

console.log(result)

// const result = f1(f2(f3(0)))
// console.log(result)